package com.novatialabs.qttt.gwt.client;

import java.util.ArrayList;
import java.util.List;

public class BaseNotation implements Notation {

  public GameModel parseGame(String g) {

    List<Move> moves = new ArrayList<Move>();
    String[] moveStrings = g.split(getMoveSeperator());

    for (String m : moveStrings) {
      moves.add(parseMove(m));
    }
    return new GameModel(moves);
  }

  public Move parseMove(String m) {
    throw new IllegalStateException("Not implemented.");
  }

  public String printGame(GameModel g) {

    StringBuilder sb = new StringBuilder();
    List<Move> moves = g.getMoves();
    if (moves.size() == 1 && moves.get(0).getState() == Move.State.NOT_PLAYED) {
      return "";
    }
    boolean first = true;
    for (Move m : moves) {
      if (first) {
        first = false;
      } else {
        sb.append(getMoveSeperator());
      }
      sb.append(printMove(m));

    }
    return sb.toString();
  }

  protected String getMoveSeperator() {
    return "\n";
  }

  public String printMove(Move m) {

    return m.getFirstMark() + "-" + m.getSecondMark() + "(" + m.getState() + ")";
  }

}
